package com.yhy.manager.listener;

import com.yhy.manager.domain.Log;
import com.yhy.manager.service.LogService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@RocketMQMessageListener(
        topic = "tanhua-logs",
        consumerGroup = "tanhua-logs-consumer"
)
public class LogMessageListener implements RocketMQListener<Map> {

    @Autowired
    private LogService logService;

    @Override
    public void onMessage(Map map) {
        System.out.println("从消息中间件获取到了:"+map);
//        1.获取传递过来的map里的内容
        Integer userId = (Integer) map.get("userId");
        String type = (String) map.get("type");
        String date = (String) map.get("date");
        Log log =new Log();
        log.setUserId(Long.valueOf(userId));
        log.setType(type);
        log.setLogTime(date);
        logService.save(log);
    }
}
